import { createApp } from 'vue'
import App from './App.vue'
import { installPinia } from '@/stores'
import { installRouter } from '@/router'
import AppLoading from '@/components/AppLoading.vue'

async function startup() {
  // 载入全局 loading 加载状态
  const appLoading = createApp(AppLoading)
  appLoading.mount('#appLoading')
  // 创建 vue 实例
  const app = createApp(App)
  // 注册模块 Pinia
  await installPinia(app)
  // 注册模块 Vue-router
  await installRouter(app)
  // 注册模块 指令/静态资源
  Object.values(
    import.meta.glob('./modules/*.js', {
      eager: true
    })
  ).map((module) => {
    app.use(module)
  })
  // 卸载载入动画
  appLoading.unmount()
  // 挂载
  app.mount('#app')
}

startup()
